import type { SDKConfig } from '../types';

export class ConfigManager {
  private config: Required<SDKConfig>;

  constructor(config: SDKConfig) {
    this.config = {
      apiKey: config.apiKey,
      baseURL: config.baseURL,
      projectId: config.projectId || '',
      userId: config.userId || '',
      platform: config.platform || 'H5', // 添加platform默认值
      enableAutoReport: config.enableAutoReport ?? true,
      enableConsoleLog: config.enableConsoleLog ?? false,
      maxRetryCount: config.maxRetryCount ?? 3,
      retryDelay: config.retryDelay ?? 1000,
      batchSize: config.batchSize ?? 10,
      flushInterval: config.flushInterval ?? 30000,
      enablePerformanceMonitor: config.enablePerformanceMonitor ?? true,
      enableNetworkMonitor: config.enableNetworkMonitor ?? true,
      enableUserBehavior: config.enableUserBehavior ?? true,
      customFields: config.customFields || {}
    };
  }

  getConfig(): Required<SDKConfig> {
    return { ...this.config };
  }

  updateConfig(updates: Partial<SDKConfig>): void {
    this.config = { ...this.config, ...updates };
  }

  getApiKey(): string {
    return this.config.apiKey;
  }

  getBaseURL(): string {
    return this.config.baseURL;
  }
}